<?php

/**
 * @package Bike
 * @subpackage Request
 */

/**
 *
 * Class for handling request data
 * @author Chrome
 * @package Bike
 * @subpackage Request
 */
class Bike_Request implements Bike_IRequest {
	
	/**
	 *
	 * $_SERVER vars
	 * @var array
	 */
	protected $server;
	
	/**
	 *
	 * $_ENV vars
	 * @var array;
	 */
	protected $env;
	
	/**
	 *
	 * $_GET vars
	 * @var array
	 */
	protected $get;
	
	/**
	 *
	 * $_POST vars
	 * @var array
	 */
	protected $post;
	
	/**
	 *
	 * $_COOKIE vars
	 * @var array
	 */
	protected $cookie;
	
	/**
	 *
	 * $_REQUEST vars
	 * @var array
	 */
	protected $request;
	
	/**
	 *
	 * Requested path
	 * @var string
	 */
	protected $path = '';

	/**
	 *
	 * Constructor
	 */
	public function __construct(){
		$this->server = &$_SERVER;
		$this->env = &$_ENV;
		$this->get = &$_GET;
		$this->post = &$_POST;
		$this->cookie = &$_COOKIE;
		$this->request = &$_REQUEST;
		if(!isset($this->server['REQUEST_URI'])){
			$this->server['REQUEST_URI'] = '';
		}
		$this->path = parse_url($this->server['REQUEST_URI'], PHP_URL_PATH);
	}

	/**
	 * (non-PHPdoc)
	 * @see Bike_IRequest::getServerVar()
	 */
	public function getServerVar($varname){
		if(isset($this->server[$varname])){
			return $this->server[$varname];
		}
		return null;
	}
	
	/**
	 * (non-PHPdoc)
	 * @see Bike_IRequest::getEnvVar()
	 */
	public function getEnvVar($varname){
		if(isset($this->env[$varname])){
			return $this->env[$varname];
		}
		return null;
	}

	/**
	 * (non-PHPdoc)
	 * @see Bike_IRequest::getGetVar()
	 */
	public function getGetVar($varname){
		if(isset($this->get[$varname])){
			return $this->get[$varname];
		}
		return null;
	}

	/**
	 * (non-PHPdoc)
	 * @see Bike_IRequest::getPostVar()
	 */
	public function getPostVar($varname){
		if(isset($this->post[$varname])){
			return $this->post[$varname];
		}
		return null;
	}

	/**
	 * (non-PHPdoc)
	 * @see Bike_IRequest::getPostVars()
	 */
	public function getPostVars(){
		return $this->post;
	}

	/**
	 * (non-PHPdoc)
	 * @see Bike_IRequest::getCookieVar()
	 */
	public function getCookieVar($varname){
		if(isset($this->cookie[$varname])){
			return $this->cookie[$varname];
		}
		return null;
	}

	/**
	 * (non-PHPdoc)
	 * @see Bike_IRequest::getRequestVar()
	 */
	public function getRequestVar($varname){
		if(isset($this->request[$varname])){
			return $this->request[$varname];
		}
		return null;
	}

	/**
	 * (non-PHPdoc)
	 * @see Bike_IRequest::getRequestVars()
	 */
	public function getRequestVars(){
		return $this->request;
	}

	/**
	 * (non-PHPdoc)
	 * @see Bike_IRequest::getPath()
	 */
	public function getPath(){
		return $this->path;
	}
}
